--
-- Author: ping.wang
-- Date: 2019-03-08 11:03:34
--
-- PvpDuelRecordRender
--

local ClassRef = app.mvc.createListViewCell(...)
local NewTeamMemberHeadRender = require("app.team.views.renders.NewTeamMemberHeadRender")

--data =
function ClassRef.createWithData(data, node)
    local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.PvpDuelRecordNode))
    if node == nil then
        ccui.Helper:doLayout(sprite)
    end
    sprite:init(data)
    return sprite
end
function ClassRef.create(node)
    return ClassRef.createWithData(nil, node)
end

--
function ClassRef:init(data)
    self.super.init(self, data)
    self._playerIcon = NewTeamMemberHeadRender.create( self._ui.head )

    self._ui.Button_1:setVisible(true) --回放按钮隐藏掉
    self._ui.Button_2:setVisible(true)

    self._ui.Button_1:addClickEventListener(function()
        --分享
        --app:sendMsg("IMRoomController", "shareItem", Enums.TipsType.duel, "熊大", "熊二", "xiongxiong")
        display.pushToast(L("tips_1000034"))
    end)

    self._ui.Button_2:addClickEventListener(function()
        display.pushToast(L("tips_1000034"))
        --分享
        --app:sendMsg("IMRoomController", "shareItem", Enums.TipsType.duel, "熊大", "熊二", "xiongxiong")
    end)


    self:setContentSize( self._ui.Panel:getContentSize() )
    self:refresh()
end

--data 是 PvpDuelRecordVo
function ClassRef:refresh()
    if self._data then
        self:setVisible( true )

        local data = self._data
        local isAttacker = data:isAttacker()
        self._ui.img_def:setVisible(not isAttacker)
        self._ui.img_atk:setVisible(isAttacker)
        local udbInfo = data:getEnemyInfo()
        self._playerIcon:setData(udbInfo)
        self._ui.Text_name:setString(udbInfo.name)
        self._ui.Text_time:setString(data:getDisplayTimeStr())
        local rankChange = data:getRankChange()
        local isWin = data:isWin()
        self._ui.img_win:setVisible(isWin)
        self._ui.img_fail:setVisible(not isWin)

        if rankChange ~= 0 then
            self._ui.Text_num:setVisible(true)
            if isWin then
                self._ui.img_jt1:setVisible(true)
                self._ui.img_jt2:setVisible(false)
            else
                self._ui.img_jt1:setVisible(false)
                self._ui.img_jt2:setVisible(true)
            end
            self._ui.Text_num:setString(tostring(math.abs(rankChange)))
        else
            self._ui.Text_num:setVisible(false)
            self._ui.img_jt1:setVisible(false)
            self._ui.img_jt2:setVisible(false)
        end

    else
        self:setVisible( false )
    end
end

function ClassRef:onBtnClick(cb)
    self._onClick = cb
end

return ClassRef
